﻿function wDojo()
{
	var wdojo = dojo;
	var wdojox = dojox;

	var _wdojoObj =
	{
		declare: function(namespace, parent, body)
		{
			if (wdojo.declare === undefined)
				wdojo.require("dojo/_base/declare");
			return wdojo.declare(namespace, parent, body);
		},

		require: require,

		requirePath: wdojo.require,

		provide: wdojo.provide,

		on: (function()
		{
			if (wdojo.on === undefined)
				wdojo.require("dojo.on");
			return wdojo.on;
		})(),

		partial: wdojo.partial,

		hitch: wdojo.hitch,

		byId: function(id)
		{
			return document.getElementById(id);
		},

		hasClass: (function()
		{
			if (wdojo.hasClass === undefined)
				wdojo.require("dojo");
			return wdojo.hasClass;
		})(),

		addClass: (function()
		{
			if (wdojo.addClass === undefined)
				wdojo.require("dojo");
			return wdojo.addClass;
		})(),

		removeClass: wdojo.removeClass,

		toggleClass: wdojo.toggleClass,

		color: function(val)
		{
			return wdojo.Color(val);
		},

		setObject: function(objnamespace, obj, context)
		{
			wdojo.setObject(objnamespace, obj);
		},

		registerModulePath: function(name, path)
		{
			wdojo.registerModulePath(name, path);
		},

		ready: function(fn)
		{
			wdojo.ready(fn);
		},

		define: function(dependencies, fn)
		{
			top.define(dependencies, fn);
		},

		queryToObject: function(query)
		{
			return wdojo.queryToObject(query);
		},

		attr: function(node, attr, value)
		{
			wdojo.attr(node, attr, value);
		},

		array: function(browser)
		{
			var res;
			require(["dojo/_base/array"], function(arrayObject)
			{
				res = arrayObject;
			});

			return res;
		},

		has: function(browser)
		{
			var res;
			require(["dojo/has", "dojo/sniff"], function(has)
			{
				res = has(browser);
			});

			return res;
		},

		query: function(selector)
		{
			return wdojo.query(selector);
		}
	};

	var wColor = function(value)
	{
		var wcolor = null,
			colorobj = null;

		_wdojoObj.require(["dojo/_base/Color"], function(Color)
		{
			wcolor = Color;
			colorobj = new Color(value);
		});

		this.fromHex = wcolor.fromHex;
		this.fromRgb = wcolor.fromRgb;

		return colorobj;
	};

	var xml =
	{
		textContent: (function()
		{
			if (wdojox.xml === undefined || wdojox.xml.parser === undefined)
				return wdojo.require("dojox.xml.parser").textContent;
			return wdojox.xml.parser.textContent;
		})(),

		parse: (function()
		{
			if (wdojox.xml === undefined || wdojox.xml.parser === undefined)
				return wdojo.require("dojox.xml.parser").parse;
			return wdojox.xml.parser.parse;
		})(),

		innerXML: (function()
		{
			if (wdojox.xml === undefined || wdojox.xml.parser === undefined)
				return wdojo.require("dojox.xml.parser").innerXML;
			return wdojox.xml.parser.innerXML;
		})()
	};

	var dojoNode = function(selectorOrNode)
	{
		wdojo.require("dojo.NodeList-traverse");
		var node = wdojo.query(selectorOrNode);
		return {
			parent: function(selector)
			{
				return node.parent(selector);
			},
			prev: function(selector)
			{
				return node.prev(selector);
			},
		};
	};

	function trim(str)
	{
		return wdojo.trim(str);
	}

	return {
		Declare: function(namespace, parent, body)
		{
			return _wdojoObj.declare(namespace, parent, body);
		},

		Require: _wdojoObj.require,

		RequirePath: _wdojoObj.requirePath,

		Provide: _wdojoObj.provide,

		On: _wdojoObj.on,

		Partial: _wdojoObj.partial,

		Hitch: _wdojoObj.hitch,

		ById: function(id)
		{
			return _wdojoObj.byId(id);
		},

		Xml: xml,

		HasClass: _wdojoObj.hasClass,

		AddClass: _wdojoObj.addClass,

		RemoveClass: _wdojoObj.removeClass,

		ToggleClass: _wdojoObj.toggleClass,

		Color: wColor,

		DojoNode: dojoNode,

		SetObject: function(objnamespace, obj, context)
		{
			_wdojoObj.setObject(objnamespace, obj);
		},

		RegisterModulePath: function(name, path)
		{
			_wdojoObj.registerModulePath(name, path);
		},

		Ready: function(fn)
		{
			_wdojoObj.ready(fn);
		},

		Define: function(dependencies, fn)
		{
			_wdojoObj.define(dependencies, fn);
		},

		Trim: trim,

		QueryToObject: function(query)
		{
			return _wdojoObj.queryToObject(query);
		},

		Query: function(selector)
		{
			return _wdojoObj.query(selector);
		},

		Attr: function(node, attr, value)
		{
			_wdojoObj.attr(node, attr, value);
		},

		Array: _wdojoObj.array(),

		Has: function(browser)
		{
			return _wdojoObj.has(browser);
		}
	};
}